// HSS.Data.WrappedDataContainer.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       WrappedDataContainer.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Data
{
	#region Using Directives
	using System;
	using System.Collections.ObjectModel;
	using System.Globalization;
	#endregion

	#region WrappedDataContainer
	/// <summary>
	/// WrappedDataContainer is a simple implementation of IDataContainer and provides 
	/// wrapper functionality so that other objects can be shared with HSS Objects 
	/// and Components via the <see cref="IDataContainer"/> interface. Normally, a
	/// class would have properties representing it's data (object model), but this
	/// is a wrapper class and just has the one property (this.Data) which contains
	/// the wrapped object.
	/// </summary>
	[Serializable]
	public class WrappedDataContainer : IDataContainer
	{
		/// <summary>
		/// Default CTOR
		/// </summary>
		public WrappedDataContainer(string id, object data)
		{
			this._id = id;
			this._name = id;
			this._data = data;
		}
		/// <summary>
		/// Default CTOR
		/// </summary>
		public WrappedDataContainer(string id, string name, object data)
		{
			this._id = id;
			this._name = name;
			this._data = data;
		}

		#region IDataContainer Members
		/// <summary>
		/// The Unique Id for the Data contained in an instance of this class.
		/// </summary>
		public string Id
		{
			get { return _id; }
			set { _id = value; }
		} string _id;
		/// <summary>
		/// The friendly name to refer to this instance by.
		/// </summary>
		public string Name
		{
			get { return _name; }
			set { _name = value; }
		} string _name;
		/// <summary>
		/// The data contained in this object
		/// </summary>
		public object Data
		{
			get { return _data; }
			set { _data = value; }
		} object _data;
		#endregion

		/// <summary>
		/// Creates a Collection of type DataContainer using the order index as the Id and Name
		/// </summary>
		/// <param name="listData">The IEnumerable list of objects</param>
		/// <returns>A Collection of type DataContainer containing the objects</returns>
		public static Collection<WrappedDataContainer> CreateWrappedDataContainerCollection(System.Collections.IEnumerable listData)
		{
			Collection<WrappedDataContainer> dataList = new Collection<WrappedDataContainer>();
			int counter = 0;
			foreach (object obj in listData)
				dataList.Add(new WrappedDataContainer((counter++).ToString(CultureInfo.InvariantCulture), obj));
			return dataList;
		}
		/// <summary>
		/// Creates a Collection of type IDataContainer using the order index as the Id and Name
		/// </summary>
		/// <param name="listData">The IEnumerable list of objects</param>
		/// <returns>A Collection of type IDataContainer containing the objects</returns>
		public static Collection<IDataContainer> CreateIDataContainerCollection(System.Collections.IEnumerable listData)
		{
			Collection<IDataContainer> dataList = new Collection<IDataContainer>();
			int counter = 0;
			foreach (object obj in listData)
				dataList.Add(new WrappedDataContainer((counter++).ToString(CultureInfo.InvariantCulture), obj));
			return dataList;
		}
	}
	#endregion
}